package com.homwee.listMenu.util;

import java.util.List;


import com.homwee.listMenu.util.view.ItemHaveSub;
import com.homwee.listMenu.util.view.ItemOptionInputView;
import com.homwee.listMenu.util.view.ItemOptionTextView;
import com.homwee.listMenu.util.view.ItemOptionView;
import com.homwee.listMenu.util.view.ItemProgressBar;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


public class MenuItemAdapter extends BaseAdapter{

	List<MenuItemData> mMenuDataList =null;
	Context mContext;
	public MenuItemAdapter(Context mContext){
		super();
		this.mContext =mContext;
	}
	public void init(List<MenuItemData> mMenuDataList){
		this.mMenuDataList =mMenuDataList;
	}
	public int getCount() {
		// TODO Auto-generated method stub
		int count =0;
		if (mMenuDataList != null) {
			count =mMenuDataList.size();
		}

		//Log.v("tv","getCount =" +count);
		return count;
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		//Log.v("tv","getView =" +arg0);
		MenuItemView menuItem = null;
		MenuItemData itemData=mMenuDataList.get(arg0);
		switch (itemData.mItemType) {
		case EN_OPTIONVIEW:
			if (itemData.getView() == null) {
				menuItem = new ItemOptionView(mContext);
				menuItem.init(itemData);
			} else {
				menuItem = itemData.getView();
			}

			break;
		case EN_PROGRESSBAR:
			if (itemData.getView() == null) {
				menuItem = new ItemProgressBar(mContext);
				menuItem.init(itemData);
			} else {
				menuItem = itemData.getView();
			}

			break;
		case EN_HAVESUBCHILD:
			if (itemData.getView() == null) {
				menuItem = new ItemHaveSub(mContext);
				menuItem.init(itemData);
			} else {
				menuItem = itemData.getView();
			}

			break;	
		case EN_OPTIONINPUTVIEW:
			if (itemData.getView() == null) {
				menuItem = new ItemOptionInputView(mContext);
				menuItem.init(itemData);
			} else {
				menuItem = itemData.getView();

			}

			break;	

		case EN_OPTIONTEXTVIEW:
			if (itemData.getView() == null) {
				menuItem = new ItemOptionTextView(mContext);
				menuItem.init(itemData);
			} else {
				menuItem = itemData.getView();

			}

			break;	
			
		default:
			break;
		}
		return menuItem;
	}
}